﻿using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace VSTweaker.UI.ViewModels
{
    public class ComponentsViewModel : INotifyPropertyChanged
    {
        public ComponentsViewModel(VisualStudioVersion version)
        {
            if (version == null)
            {
                return;
            }
            var components = new List<ComponentType>();

            components.Add(new ComponentType(String.Empty, "Editors", version.Version, version.Instance));
            components.Add(new ComponentType(String.Empty, "Packages", version.Version, version.Instance));
            components.Add(new ComponentType(String.Empty, "Projects", version.Version, version.Instance));
            components.Add(new ComponentType("Name", "Services", version.Version, version.Instance));
            components.Add(new ComponentType("Name", "ToolWindows", version.Version, version.Instance));
            

            ComponentTypes = components;
        }

        private ComponentType _selectedComponentType;
        private RegistryItem _selectedRegistryItem;
        private IEnumerable<RegistryItem> _registryItems;

        public ComponentType SelectedComponentType
        {
            get
            {
                return _selectedComponentType;
            }
            set
            {
                _selectedComponentType = value;
                OnPropertyChaned("SelectedComponentType");
                RegistryItems = value.RegistryItems;
            }
        }

        public RegistryItem SelectedRegistryItem
        {
            get
            {
                return _selectedRegistryItem;
            }
            set
            {
                _selectedRegistryItem = value;
                OnPropertyChaned("SelectedRegistryItem");
            }
        }

        public IEnumerable<ComponentType> ComponentTypes { get; set; }

        public IEnumerable<RegistryItem> RegistryItems
        {
            get
            {
                return _registryItems;
            }
            set
            {
                _registryItems = value;
                OnPropertyChaned("RegistryItems");
                SelectedRegistryItem = null;
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChaned(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
